package com.lsht.web.controller.siwei;

import com.github.pagehelper.PageInfo;
import com.lsht.common.bo.IdListAcceptBo;
import com.lsht.common.core.controller.BaseController;
import com.lsht.common.core.domain.AjaxResult;
import com.lsht.common.core.page.TableDataInfo;
import com.lsht.system.domain.siwei.SiweiDevice;
import com.lsht.system.domain.siwei.SiweiImg;
import com.lsht.system.domain.siwei.SiweiModel;
import com.lsht.system.service.siwei.SiweiModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 型号管理Controller
 *
 * @author zyc
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/siwei/model")
@Api(value = "SiweiModel" , description = "型号管理" , tags = "型号管理")
public class SiweiModelController extends BaseController {
    @Autowired
    private SiweiModelService siweiModelService;

    /**
     * 新增型号管理
     */
    @PostMapping(ADD_FUNCTION_URL)
    @ApiOperation(value = ADD_FUNCTION, httpMethod = "POST" , response = AjaxResult.class, tags = "型号管理")
    public AjaxResult genAdd(@RequestBody SiweiModel siweiModel) {
        return toAjax(siweiModelService.genAdd(siweiModel));
    }
    /**
     * 删除型号管理
     */
    @PostMapping(DELETE_BY_ID_FUNCTION_URL)
    @ApiOperation(value = DELETE_BY_ID_FUNCTION, httpMethod = "POST" , response = AjaxResult.class, tags = "型号管理")
    public AjaxResult genDeleteById(@RequestBody IdListAcceptBo idListAcceptBo) {
        List<String> idList = idListAcceptBo.getIdList();
        if (CollectionUtils.isNotEmpty(idList)) {
            return toAjax(siweiModelService.genDeleteById(idList));
        }
        return AjaxResult.error();
    }
    /**
     * 修改型号管理
     */
    @PostMapping(UPDATE_BY_ID_FUNCTION_URL)
    @ApiOperation(value = UPDATE_BY_ID_FUNCTION, httpMethod = "POST" , response = AjaxResult.class, tags = "型号管理")
    public AjaxResult genUpdateById(@RequestBody SiweiModel siweiModel) {
        return toAjax(siweiModelService.genUpdateById(siweiModel));
    }
    /**
     * 查询型号管理列表
     */
    @PostMapping(QUERY_LIST_FUNCTION_URL)
    @ApiOperation(value = QUERY_LIST_FUNCTION, httpMethod = "POST" , response =  SiweiModel.class, tags = "型号管理")
    public AjaxResult genQueryList(@RequestBody SiweiModel siweiModel) {
        startPage();
        List<SiweiModel> list = siweiModelService.genQueryList(siweiModel);
        return AjaxResult.success(new PageInfo<>(list));
    }

    /**
     * 根据id查询型号详情信息
     */
    @PostMapping(QUERY_BY_ID_FUNCTION_URL)
    @ApiOperation(value = QUERY_BY_ID_FUNCTION, httpMethod = "POST", response = SiweiDevice.class, tags = "型号管理")
    public AjaxResult genQueryById(@RequestBody SiweiModel siweiModel) {
        SiweiModel model = siweiModelService.genQueryById(siweiModel);
        return AjaxResult.success(model);
    }
}
